package com.enjoyor.soa.traffic.core.efoms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.core.efoms.domain.DeviceWranInfo;
import com.enjoyor.soa.traffic.core.efoms.domain.WranTacticsInfo;
import com.enjoyor.soa.traffic.core.efoms.mapper.IDeviceWranInfoMapper;
import com.enjoyor.soa.traffic.core.efoms.mapper.IWranTacticsInfoMapper;
import com.enjoyor.soa.traffic.core.efoms.service.IDeviceWranInfoService;
import com.enjoyor.soa.traffic.core.efoms.service.IWranTacticsService;
import com.enjoyor.soa.traffic.frame.logger.IPubLogMapper;
import com.enjoyor.soa.traffic.util.enums.log.LogInfoDic;
import com.enjoyor.soa.traffic.util.helper.LoggerHelper;
import com.enjoyor.soa.traffic.util.helper.TimeHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;


@Service
@Transactional
@SuppressWarnings("rawtypes")
public class WranTacticsService implements IWranTacticsService {

    @Autowired
    private IWranTacticsInfoMapper wranTacticsInfoMapper;

    @Autowired
    private IPubLogMapper pubLogMapper;

    @Override
    public WranTacticsInfo selectWranTacticsById(String tacticsId){
        return wranTacticsInfoMapper.selectById(tacticsId);
    }
    
    @Override
	public List<WranTacticsInfo> selectWranTacticsList(String tacticsId, String tacticsLevelCode, 
			String wranTypeCode, String wranLevelCode, String devTypeCode, String devId){
    	try {
	    	Map<String,Object> paramT = new HashMap<String ,Object>();
	    	paramT.put("tacticsId", tacticsId);
	    	paramT.put("tacticsLevelCode", tacticsLevelCode);
	    	paramT.put("wranTypeCode", wranTypeCode);
	    	paramT.put("wranLevelCode", wranLevelCode);
	    	paramT.put("devTypeCode", devTypeCode);
	    	paramT.put("devId", devId);
	    	return wranTacticsInfoMapper.selectWranTacticsList(paramT);
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    @Override
    public String insertWranTacticsInfo(WranTacticsInfo wranTacticsInfo, String personName){
    	try {
	    	// 默认操作记录信息
	        String tacticsId = "T" + TimeHelper.getUniqueString();
	        wranTacticsInfo.setTacticsId(tacticsId);
	        wranTacticsInfo.setCreateTime(TimeHelper.dateToLongString());
	        wranTacticsInfo.setUpdateTime(TimeHelper.dateToLongString());
	        wranTacticsInfoMapper.insert(wranTacticsInfo);
	        pubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_INSERT.getCode(),
	                String.format("添加报警策略编号:{%s} 操作成功!", new Object[] { tacticsId }),
	                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_WRAN_MANAGEMENT.getMessage());
	        return tacticsId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    @Override
    public String updateWranTacticsInfo(WranTacticsInfo wranTacticsInfo, String personName){
    	try {
	    	String tacticsId = wranTacticsInfo.getTacticsId();
	        wranTacticsInfo.setUpdateTime(TimeHelper.dateToLongString());
	    	wranTacticsInfoMapper.updateByIdSelective(wranTacticsInfo);
	        pubLogMapper.saveNoramlLogInfo(personName,null, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
	                String.format("修改报警策略编号:{%s} 操作成功!", new Object[] { tacticsId }),
	                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_WRAN_MANAGEMENT.getMessage());
	        return tacticsId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    @Override
    public String deleteWranTacticsInfo(String tacticsId, String personName){
    	try {
    		wranTacticsInfoMapper.deleteById(tacticsId);
	        pubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_DELETE.getCode(),
	                String.format("删除报警策略编号:{%s} 操作成功!", new Object[] { tacticsId }),
	                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_WRAN_MANAGEMENT.getMessage());
	        return tacticsId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    
}
